import path from 'node:path'
import process from 'node:process'
import {defineConfig, loadEnv} from 'vite'
import createVitePlugins from './vite/plugins'
import {esbuildPluginMonacoEditorNls, Languages} from "./monaco/nls";
import zh_hans from './monaco/zh.json'
// https://vitejs.dev/config/
export default async ({mode, command}) => {
  const env = loadEnv(mode, process.cwd())
  return defineConfig({
    base: './',
    // 开发服务器选项 https://cn.vitejs.dev/config/#server-options
    server: {
      port: 9009,
    },
    plugins: createVitePlugins(mode, command === 'build'),
    optimizeDeps: {
      esbuildOptions: {
        plugins: [
          // 开发环境下通过esbuild插件进行汉化
          esbuildPluginMonacoEditorNls({
            locale: Languages.zh_hans,
            localeData: zh_hans,
          }),
        ],
      },
    },
    // 构建
    css: {
      preprocessorOptions: {
        scss: {}
      }
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        '#': path.resolve(__dirname, 'src/types'),
      },
    },
  })
}
